#include "forkos/ega.h"
#include "forkos/multiboot.h"

void multiboot_traverse_info(multiboot_boot_info_header_t *info_tags) {
    uint32_t tag_start = (uint32_t)info_tags + 0x8;
    uint32_t total_size = info_tags->total_size;
    uint32_t count = 0;
    ega_print_string("Total boot info size: ", 0x1f);
    ega_print_int(total_size, 0x1f);
    ega_print_string("\n", 0x1f);

        
    ega_print_string("Found tag", 0x1f);
    
    uint32_t current_type;
    uint32_t current_size;
    while (1) {
        current_type = ((multiboot_tag_header_t*)tag_start)->type;
        current_size = ((multiboot_tag_header_t*)tag_start)->size;

        // as per multiboot2 spec
        if (current_type == 0) {
            break;
        }
        ega_print_string(" ", 0x1f);
        ega_print_int(current_type, 0x1f);
        
        tag_start += current_size;
        if (tag_start % 8 != 0) {
            tag_start += 8 - (tag_start % 8);
        }
 
        count++;
    }
    
    ega_print_string("\nTotal boot info's read: ", 0x1f);
    ega_print_int(count, 0x1f);
    ega_print_string("\n", 0x1f);
    
    ega_print_string("Traversal done\n", 0x1f);
}